package com.webchat.client.payment.controller;


import com.webchat.client.payment.service.ResourceBehaviorService;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.config.annotation.BehaviorLimiter;
import com.webchat.common.config.annotation.ValidateLogin;
import com.webchat.common.helper.SessionHelper;
import com.webchat.domain.vo.request.act.ResourceBehaviorRequestVO;
import com.webchat.rmi.act.IResourceBehaviorClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/client-service/resource")
public class ResourceBehaviorController {


    @Autowired
    private ResourceBehaviorService resourceBehaviorService;

    /**
     * 资源基础互动操作
     *
     * @param resourceBehaviorRequest
     * @return
     */
    @ValidateLogin
    @BehaviorLimiter(time = 1000L)
    @PostMapping("/behavior")
    APIResponseBean<Long> behavior(@RequestBody ResourceBehaviorRequestVO resourceBehaviorRequest) {

        resourceBehaviorRequest.validateRequestParam();
        String userId = SessionHelper.getCurrentUserId();
        resourceBehaviorRequest.setUserId(userId);
        return APIResponseBeanUtil.success(
                resourceBehaviorService.behavior(resourceBehaviorRequest));
    }

    /**
     * 取消资源基础互动操作
     *
     * @param resourceBehaviorRequest
     * @return
     */
    @ValidateLogin
    @BehaviorLimiter(time = 1000L)
    @PostMapping("/cancelBehavior")
    APIResponseBean<Long> cancelBehavior(@RequestBody ResourceBehaviorRequestVO resourceBehaviorRequest) {

        resourceBehaviorRequest.validateRequestParam();
        String userId = SessionHelper.getCurrentUserId();
        resourceBehaviorRequest.setUserId(userId);
        return APIResponseBeanUtil.success(
                resourceBehaviorService.cancelBehavior(resourceBehaviorRequest));
    }


}
